const express = require("express");
// 导入文章分类的路由处理函数模块
const artcate_handler = require("../router_handler/artcate");

const router = express.Router();
// 1.导入验证表单数据的中间件
const expressJoi = require("@escook/express-joi");

// 2.导入需要验证的规则对象
const {
  add_cate_schema,
  del_cate_schema,
  get_cate_schema,
  update_cate_schema,
} = require("../schema/artcate");

router.get("/cates", artcate_handler.getArticleCates);
// 新增文章分类
router.post(
  "/insertCates",
  expressJoi(add_cate_schema),
  artcate_handler.insertArticleCates
);

// 根据ID删除文章分类
router.get(
  "/deleteCates/:id",
  expressJoi(del_cate_schema),
  artcate_handler.deleteCates
);
// 根据 Id 获取文章分类
router.get(
  "/cates/:id",
  expressJoi(get_cate_schema),
  artcate_handler.getArtCateById
);
// 根据ID更新数据 并查询分类名称和别名是否被占用
router.post(
  "/updateCate",
  expressJoi(update_cate_schema),
  artcate_handler.updateCateById
);

module.exports = router;
